﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WindowsFormsApp4.DLL;

namespace WindowsFormsApp4
{
    public partial class RegisterForm : Form
    {
        public RegisterForm()
        {
            InitializeComponent();
        }

        DbUse dbUse = new DbUse();
        /// <summary>
        /// 注册
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            string UserName = tbUsername.Text.Trim();
            string PassWord = tbPassword.Text.Trim();
            string RePassWord = tbRePassword.Text.Trim();

            if (string.IsNullOrWhiteSpace(UserName) || string.IsNullOrWhiteSpace(PassWord))
            {
                MessageBox.Show("注册信息不能为空", "提示");
            }
            else if (!RePassWord.Equals(PassWord)) 
            {
                MessageBox.Show("请检查两次输入的密码是否一致", "提示");
            }

            else
            {
                int resNum=  dbUse.OnRegister(UserName, PassWord);
                if (resNum>0)
                {
                    MessageBox.Show("注册成功", "提示");
                    LoginForm loginForm = new LoginForm();
                    loginForm.Show();
                    this.Hide();
                }
            }
           
        }


        /// <summary>
        /// 取消
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {
            LoginForm loginForm = new LoginForm();
            loginForm.Show();
            this.Hide();
        }
    }
}
